package com.chat.admin.controller;


import com.chat.admin.annotate.IsNumeric;
import com.chat.admin.domain.DTO.ADD.AddAdminDTO;
import com.chat.admin.domain.DTO.AdminDTO;
import com.chat.admin.domain.DTO.EDIT.EditAdminDTO;
import com.chat.admin.domain.VO.AdminVO;
import com.chat.admin.service.IAdminService;
import com.chat.common.form.ListForm;
import com.chat.common.vo.R;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 管理员账户模块
 */
@RestController
@Validated
@RequestMapping("/admin/system")
public class AdminController {

    @Autowired
    IAdminService iAdminService;

    /**
     * 获取管理员列表
     * @param adminDTO
     * @return
     */
    @PostMapping("/getAdminList")
    public R<ListForm<AdminVO>> getAdminList(@Validated @RequestBody  AdminDTO adminDTO){
        return iAdminService.getAdminList(adminDTO);
    }

    /**
     * 添加管理员账户
     * @param addAdminDTO
     * @return
     */
    @PostMapping("/addOneAdmin")
    public R addOneAdmin(@Validated @RequestBody AddAdminDTO addAdminDTO){
        return iAdminService.addOneAdmin(addAdminDTO);
    }

    /**
     * Excel批量添加账户
     * @param file
     * @return
     */
    @PostMapping("/addExcelAdmin")
    public R<?> addExcelUserAccount(MultipartFile file) {
        return iAdminService.addExcelAdmin(file);
    }

    /**
     * 禁用管理员账号
     * @param userID
     * @return
     */
    @GetMapping("/disableAccount")
    public R<?> DisableAccount(@RequestParam @NotBlank(message = "ID不能为空") @IsNumeric(message = "userID不是数字") String userID) {
        return iAdminService.DisableAccount(Long.valueOf(userID));
    }

    /**
     * 启用管理员账号
     * @param userID
     * @return
     */
    @GetMapping("/enableAccount")
    public R<?> EnableAccount(@RequestParam @NotBlank(message = "ID不能为空") @IsNumeric(message = "userID不是数字") String userID){
        return iAdminService.EnableAccount(Long.valueOf(userID));
    }

    /**
     * 更新管理员信息
     * @param editAdminDTO
     * @return
     */
    @PostMapping("/editAdmEdit")
    public R EditAdmin(@Validated @RequestBody EditAdminDTO editAdminDTO){
        return iAdminService.updateAdmin(editAdminDTO);
    }
}
